//
//  HSLotteryDetailCell.m
//  HolyShit
//
//  Created by Robin on 2017/4/30.
//  Copyright © 2017年 HolyShit. All rights reserved.
//

#import "HSLotteryBallDetailCell.h"

@implementation HSLotteryBallDateModel

- (instancetype)init
{
    if (self = [super init]) {
        self.detailModels = @[].mutableCopy;
    }
    return self;
}

@end

@implementation HSLotteryBallDetailModel

@end

@interface HSLotteryBallDetailCell ()

@property (nonatomic, strong) UILabel *leagueLb;
@property (nonatomic, strong) UILabel *numLb;
@property (nonatomic, strong) UILabel *homeLb;
@property (nonatomic, strong) UILabel *scoreLb;
@property (nonatomic, strong) UILabel *guestLb;
@property (nonatomic, strong) UILabel *emptyLb;

@end

@implementation HSLotteryBallDetailCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self commonInit];
    }
    return self;
}

- (void)commonInit
{
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    self.width = ScreenWidth;
    
    self.leagueLb = [UILabel labelWithFont:MYFont(Font24) color:HEXCOLOR(HSColorBlack)];
    self.leagueLb.textAlignment = NSTextAlignmentCenter;
    self.leagueLb.numberOfLines = 0;
    [self addSubview:self.leagueLb];
    self.numLb = [UILabel labelWithFont:MYFont(Font24) color:HEXCOLOR(HSColorBlack)];
    self.numLb.textAlignment = NSTextAlignmentCenter;
    [self addSubview:self.numLb];
    self.homeLb = [UILabel labelWithFont:MYFont(Font24) color:HEXCOLOR(HSColorBlack)];
    self.homeLb.textAlignment = NSTextAlignmentCenter;
    self.homeLb.numberOfLines = 0;
    [self addSubview:self.homeLb];
    self.guestLb = [UILabel labelWithFont:MYFont(Font24) color:HEXCOLOR(HSColorBlack)];
    self.guestLb.textAlignment = NSTextAlignmentCenter;
    self.guestLb.numberOfLines = 0;
    [self addSubview:self.guestLb];
    
    self.scoreLb = [UILabel labelWithFont:MYFont(Font30) color:HEXCOLOR(HSColorRed)];
    self.scoreLb.textAlignment = NSTextAlignmentCenter;
    [self addSubview:self.scoreLb];
    
    [self.leagueLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_lessThanOrEqualTo(15);
        make.left.mas_equalTo(0);
        make.width.mas_equalTo(ScreenWidth / 4.);
    }];
    
    [self.numLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.width.mas_equalTo(self.leagueLb);
        make.top.equalTo(self.leagueLb.mas_bottom);
        make.bottom.mas_greaterThanOrEqualTo(-10).priorityHigh();
    }];
    
    [self.homeLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.leagueLb.mas_right);
        make.top.bottom.mas_equalTo(0);
        make.width.equalTo(self.leagueLb);
    }];
    
    [self.scoreLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.homeLb.mas_right);
        make.top.bottom.width.equalTo(self.homeLb);
    }];
    
    [self.guestLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.scoreLb.mas_right);
        make.top.bottom.width.equalTo(self.homeLb);
    }];
    
    self.emptyLb = [UILabel labelWithFont:MYFont(Font32) color:HEXCOLOR(HSColorBlack)];
    self.emptyLb.textAlignment = NSTextAlignmentCenter;
    self.emptyLb.text = @"暂无赛果";
    [self addSubview:self.emptyLb];
    [self.emptyLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(0);
    }];
    
}

- (void)updateModel:(HSLotteryBallDetailModel *)model atIndex:(NSUInteger)index
{
    self.backgroundColor = index % 2 == 0 ? HEXCOLOR(HSColorSeparateLight) : WHITE_COLOR;
    if (model.HOME_TEAM.length < 1) {
        //空
        self.emptyLb.hidden = NO;
        self.emptyLb.backgroundColor = self.backgroundColor;
        return;
    }
    self.emptyLb.hidden = YES;
    self.leagueLb.text = model.LEAGUE;
    self.numLb.text = model.MATCH_NO;
    self.homeLb.text = model.HOME_TEAM;
    self.guestLb.text = model.GUEST_TEAM;
    if (model.HALF_SCORE.length > 0) {
        NSString *str = [NSString stringWithFormat:@"%@(%@)", model.SCORE, model.HALF_SCORE];
        NSMutableAttributedString *attr = [[NSMutableAttributedString alloc] initWithString:str];
        [attr addAttributes:@{NSForegroundColorAttributeName : HEXCOLOR(HSColorGray), NSFontAttributeName : MYFont(10)} range:NSMakeRange(model.SCORE.length, str.length - model.SCORE.length)];
        self.scoreLb.attributedText = attr;
    }
    else{
        self.scoreLb.text = model.SCORE;
    }
}

@end
